/*
*******************************************************************************
* ansi c source code
* file name:
*	ShowProgress.c
* abstract:
*	to show the simulation progress
* reference:
*	
*******************************************************************************
*/


/*
*******************************************************************************
*                               include files
*******************************************************************************
*/

#include <stdio.h>

/*
*******************************************************************************
*                               function files
*******************************************************************************
*/

void ShowProgress(int present_num, int total_num)
{
	int	 percentage;
	char progress_bar[51];
	int  bar_num;
	char end_figure[4] = {'\x1e', '\x11', '\x1f', '\x10'};
	int  m;

	if ( present_num == 1 )
	{
		printf("Simulation Starting ...\n\n");
	}

	percentage = 100 * present_num / total_num;
	bar_num = percentage / 2 ;

	for (m = 0; m < bar_num; m++) progress_bar[m] = '\x3e';
	for (; m < 50; m++) progress_bar[m] = '\x3d';
	progress_bar[50] = '\0';

	putchar('\r');
	printf("%s", progress_bar);
	printf("\t");

	/*to show the progress dynamicly */
	putchar(end_figure[present_num%4]);       
	putchar(end_figure[(present_num+2)%4]);

	/*to show the percentage of the progress*/
	printf(" %3d%%", percentage);

	if ( present_num == total_num )
	{
		printf("\n\nSimulation Accomplished\n\n");
	}
}


